package com.hdu.hot100.backTrack;

import java.util.ArrayList;
import java.util.List;

public class lc22 {
    class Solution {
        List<String> ans = new ArrayList<>();
        public List<String> generateParenthesis(int n) {
            f(n, n, "");
            return ans;
        }

        void f(int l, int r, String path)
        {
            if (l == 0 && r == 0)
            {
                ans.add(path);
            }
            if (l > 0) f(l - 1, r, path + "(");
            if (r > 0 && l < r) f(l, r - 1, path + ")");
        }
    }
}
